//
//  CJBaseTextField.m
//  DatangLife
//
//  Created by 陈建 on 2018/6/28.
//  Copyright © 2018年 DatangLife. All rights reserved.
//

#import "CJBaseTextField.h"

@interface CJBaseTextField ()

@end

@implementation CJBaseTextField


- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    
    self = [super initWithCoder:aDecoder];
    if (self) {
        //        self.delegate = self;
        [self addTarget:self action:@selector(textFieldChangeValue:) forControlEvents:UIControlEventEditingChanged];
    }
    return self;
}

- (void)textFieldChangeValue:(UITextField *)textField{
    textField.text =[textField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    if (textField.text.length > 0) {
        NSString *first = [textField.text substringToIndex:1];//字符串开始
        if ([first isEqualToString:@"."]) {
            textField.text =[textField.text stringByReplacingOccurrencesOfString:@"." withString:@""];
        }
    }
    
    if ([self.delegateTextField respondsToSelector:@selector(CJ_textFieldDidChangeValue:)]) {
        [self.delegateTextField CJ_textFieldDidChangeValue:textField.text];
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
